// 共阴极数码管
int a = 2;  // 定义数字接口2 连接a
int b = 3;  // 定义数字接口3 连接b
int c = 4;  // 定义数字接口4 连接c
int d = 5;  // 定义数字接口5 连接d
int e = 6;  // 定义数字接口6 连接e
int f = 7;  // 定义数字接口7 连接f
int g = 8;  // 定义数字接口8 连接g
int h = 9;  // 定义数字接口8 连接h，也就是数码管中的dp

void setup() {
  // put your setup code here, to run once:
  int i;
  for (i = 2; i <= 9; i++) {
    pinMode(i, OUTPUT);  // 设置2~9号引脚为输出模式
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  digital_0();  // 显示数字0
  delay(1000);
  digital_1();  // 显示数字1
  delay(1000);
  digital_2();  // 显示数字2
  delay(1000);
  digital_3();  // 显示数字3
  delay(1000);
  digital_4();  // 显示数字4
  delay(1000);
  digital_5();  // 显示数字5
  delay(1000);
  digital_6();  // 显示数字6
  delay(1000);
  digital_7();  // 显示数字7
  delay(1000);
  digital_8();  // 显示数字8
  delay(1000);
  digital_9();  // 显示数字9
  delay(1000);
}

// 显示数字0
void digital_0(void) {
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, LOW);
  digitalWrite(h, HIGH);
}

// 显示数字1
void digital_1(void) {
  digitalWrite(a, LOW);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
  digitalWrite(h, HIGH);
}

// 显示数字2
void digital_2(void) {
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, LOW);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, LOW);
  digitalWrite(g, HIGH);
  digitalWrite(h, HIGH);
}

// 显示数字3
void digital_3(void) {
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, HIGH);
  digitalWrite(h, HIGH);
}

// 显示数字4
void digital_4(void) {
  digitalWrite(a, LOW);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  digitalWrite(h, HIGH);
}

// 显示数字5
void digital_5(void) {
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, LOW);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  digitalWrite(h, HIGH);
}

// 显示数字6
void digital_6(void) {
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  digitalWrite(h, HIGH);
}

// 显示数字7
void digital_7(void) {
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
  digitalWrite(h, HIGH);
}

// 显示数字8
void digital_8(void) {
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  digitalWrite(h, HIGH);
}

// 显示数字9
void digital_9(void) {
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, LOW);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  digitalWrite(h, HIGH);
}